﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ReportViewerControl2005SandBox
{
    public partial class FormAPIReport : Form
    {
        public FormAPIReport()
        {
            InitializeComponent();
        }

        private void FormAPIReport_Load(object sender, EventArgs e)
        {
            var gen = new SharedReportCode.DataGenerator();
            var api_info = gen.GetAPIInformation();

            this.APIInfoBindingSource.DataSource = api_info;

            var shared_code_asm_name = SharedReportCode.ReportUtil.GetAssemblyName();
            
            // Setup the options for local report viewing
            var localreport = this.reportViewer1.LocalReport;
            localreport.AddTrustedCodeModuleInCurrentAppDomain(shared_code_asm_name);
            localreport.EnableExternalImages = true;

            this.parameterPanel1.Populate(localreport);
            this.GetUIParameters();
            this.reportViewer1.RefreshReport();
        }

        private void GetUIParameters()
        {
            var parameters = this.parameterPanel1.GetParameters(this.reportViewer1.LocalReport);
            this.reportViewer1.LocalReport.SetParameters(parameters);          
        }

        private void reportViewer1_ReportRefresh(object sender, CancelEventArgs e)
        {
            this.GetUIParameters();
        }
    }
}
